package com.mcf.world.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcf.world.entity.City;

import com.mcf.world.service.ICityService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-03-29
 */
@RestController
@RequestMapping("/world/city")
public class CityController {
    @Autowired
    ICityService cityService;

    @RequestMapping("/add")
    public String add(City city) {
        if (cityService.save(city)) {
            return "success";
        }
        return "false";
    }

    @RequestMapping("/citys")
    public List<City> citys() {
        return cityService.list();
    }

    @RequestMapping("/page")
    public List<City> page(Page<City> page, String district) {
        return cityService.selectUserPage1(new Page<City>(1, 10), "KABOL");
    }

    @RequestMapping("/eq")

    public City eq(Integer id) {
    QueryWrapper<City> queryWrapper=new QueryWrapper<City>();
    queryWrapper.eq(true,"id",(Object)id);
    return cityService.getOne(queryWrapper);

    }
    @RequestMapping("/gt")
    public List<City> gt(Integer id){
        QueryWrapper<City> queryWrapper=new QueryWrapper<City>();
        queryWrapper.gt(true,"id",(Object)id);
        return  cityService.list(queryWrapper);
    }
    @RequestMapping("/between")
    public List<City> between(Integer id1,Integer id2){
        QueryWrapper<City> queryWrapper=new QueryWrapper<City>();
        queryWrapper.between(true,"id",(Object)id1,(Object)id2);
        return  cityService.list(queryWrapper);
    }
    @RequestMapping("/like")
    public List<City> like( ){
        String countrycode ="%CH%";
        QueryWrapper<City> queryWrapper=new QueryWrapper<City>();
        queryWrapper.like(true,"countrycode",(Object)countrycode);
        return cityService.list(queryWrapper);
    }
    @RequestMapping("/in")
    public List<City> in(Integer[] ids ){
        Collection<Integer> collection= Arrays.asList(ids);
        QueryWrapper<City> queryWrapper=new QueryWrapper<City>();
        queryWrapper.in(true,"id",collection);
        return cityService.list(queryWrapper);
    }
}
